﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using GPSTrackingServerDB.Entities;
using GPSTrackingServerDB.Data;

#endregion

namespace GPSTrackingServerDB.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="ImeiProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class ImeiProviderBaseCore : EntityProviderBase<GPSTrackingServerDB.Entities.Imei, GPSTrackingServerDB.Entities.ImeiKey>
	{		
		#region Get from Many To Many Relationship Functions
		#region GetByGeoFenceIdFromGeoFenceByImei
		
		/// <summary>
		///		Gets Imei objects from the datasource by GeoFenceID in the
		///		GeoFenceByImei table. Table Imei is related to table GeoFence
		///		through the (M:N) relationship defined in the GeoFenceByImei table.
		/// </summary>
		/// <param name="_geoFenceId"></param>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByGeoFenceIdFromGeoFenceByImei(System.Int32 _geoFenceId)
		{
			int count = -1;
			return GetByGeoFenceIdFromGeoFenceByImei(null,_geoFenceId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingServerDB.Entities.Imei objects from the datasource by GeoFenceID in the
		///		GeoFenceByImei table. Table Imei is related to table GeoFence
		///		through the (M:N) relationship defined in the GeoFenceByImei table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_geoFenceId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Imei objects.</returns>
		public TList<Imei> GetByGeoFenceIdFromGeoFenceByImei(System.Int32 _geoFenceId, int start, int pageLength)
		{
			int count = -1;
			return GetByGeoFenceIdFromGeoFenceByImei(null, _geoFenceId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Imei objects from the datasource by GeoFenceID in the
		///		GeoFenceByImei table. Table Imei is related to table GeoFence
		///		through the (M:N) relationship defined in the GeoFenceByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_geoFenceId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByGeoFenceIdFromGeoFenceByImei(TransactionManager transactionManager, System.Int32 _geoFenceId)
		{
			int count = -1;
			return GetByGeoFenceIdFromGeoFenceByImei(transactionManager, _geoFenceId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets Imei objects from the datasource by GeoFenceID in the
		///		GeoFenceByImei table. Table Imei is related to table GeoFence
		///		through the (M:N) relationship defined in the GeoFenceByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_geoFenceId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByGeoFenceIdFromGeoFenceByImei(TransactionManager transactionManager, System.Int32 _geoFenceId,int start, int pageLength)
		{
			int count = -1;
			return GetByGeoFenceIdFromGeoFenceByImei(transactionManager, _geoFenceId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Imei objects from the datasource by GeoFenceID in the
		///		GeoFenceByImei table. Table Imei is related to table GeoFence
		///		through the (M:N) relationship defined in the GeoFenceByImei table.
		/// </summary>
		/// <param name="_geoFenceId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByGeoFenceIdFromGeoFenceByImei(System.Int32 _geoFenceId,int start, int pageLength, out int count)
		{
			
			return GetByGeoFenceIdFromGeoFenceByImei(null, _geoFenceId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets Imei objects from the datasource by GeoFenceID in the
		///		GeoFenceByImei table. Table Imei is related to table GeoFence
		///		through the (M:N) relationship defined in the GeoFenceByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_geoFenceId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Imei objects.</returns>
		public abstract TList<Imei> GetByGeoFenceIdFromGeoFenceByImei(TransactionManager transactionManager,System.Int32 _geoFenceId, int start, int pageLength, out int count);
		
		#endregion GetByGeoFenceIdFromGeoFenceByImei
		
		#region GetByGroupIdFromGroupsByImei
		
		/// <summary>
		///		Gets Imei objects from the datasource by GroupID in the
		///		GroupsByImei table. Table Imei is related to table Groups
		///		through the (M:N) relationship defined in the GroupsByImei table.
		/// </summary>
		/// <param name="_groupId"></param>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByGroupIdFromGroupsByImei(System.Int32 _groupId)
		{
			int count = -1;
			return GetByGroupIdFromGroupsByImei(null,_groupId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingServerDB.Entities.Imei objects from the datasource by GroupID in the
		///		GroupsByImei table. Table Imei is related to table Groups
		///		through the (M:N) relationship defined in the GroupsByImei table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_groupId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Imei objects.</returns>
		public TList<Imei> GetByGroupIdFromGroupsByImei(System.Int32 _groupId, int start, int pageLength)
		{
			int count = -1;
			return GetByGroupIdFromGroupsByImei(null, _groupId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Imei objects from the datasource by GroupID in the
		///		GroupsByImei table. Table Imei is related to table Groups
		///		through the (M:N) relationship defined in the GroupsByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_groupId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByGroupIdFromGroupsByImei(TransactionManager transactionManager, System.Int32 _groupId)
		{
			int count = -1;
			return GetByGroupIdFromGroupsByImei(transactionManager, _groupId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets Imei objects from the datasource by GroupID in the
		///		GroupsByImei table. Table Imei is related to table Groups
		///		through the (M:N) relationship defined in the GroupsByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_groupId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByGroupIdFromGroupsByImei(TransactionManager transactionManager, System.Int32 _groupId,int start, int pageLength)
		{
			int count = -1;
			return GetByGroupIdFromGroupsByImei(transactionManager, _groupId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Imei objects from the datasource by GroupID in the
		///		GroupsByImei table. Table Imei is related to table Groups
		///		through the (M:N) relationship defined in the GroupsByImei table.
		/// </summary>
		/// <param name="_groupId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByGroupIdFromGroupsByImei(System.Int32 _groupId,int start, int pageLength, out int count)
		{
			
			return GetByGroupIdFromGroupsByImei(null, _groupId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets Imei objects from the datasource by GroupID in the
		///		GroupsByImei table. Table Imei is related to table Groups
		///		through the (M:N) relationship defined in the GroupsByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_groupId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Imei objects.</returns>
		public abstract TList<Imei> GetByGroupIdFromGroupsByImei(TransactionManager transactionManager,System.Int32 _groupId, int start, int pageLength, out int count);
		
		#endregion GetByGroupIdFromGroupsByImei
		
		#region GetByNotificationIdFromNotificationsByImei
		
		/// <summary>
		///		Gets Imei objects from the datasource by NotificationID in the
		///		NotificationsByImei table. Table Imei is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationsByImei table.
		/// </summary>
		/// <param name="_notificationId"></param>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByNotificationIdFromNotificationsByImei(System.Int32 _notificationId)
		{
			int count = -1;
			return GetByNotificationIdFromNotificationsByImei(null,_notificationId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets GPSTrackingServerDB.Entities.Imei objects from the datasource by NotificationID in the
		///		NotificationsByImei table. Table Imei is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationsByImei table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_notificationId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Imei objects.</returns>
		public TList<Imei> GetByNotificationIdFromNotificationsByImei(System.Int32 _notificationId, int start, int pageLength)
		{
			int count = -1;
			return GetByNotificationIdFromNotificationsByImei(null, _notificationId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Imei objects from the datasource by NotificationID in the
		///		NotificationsByImei table. Table Imei is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationsByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_notificationId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByNotificationIdFromNotificationsByImei(TransactionManager transactionManager, System.Int32 _notificationId)
		{
			int count = -1;
			return GetByNotificationIdFromNotificationsByImei(transactionManager, _notificationId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets Imei objects from the datasource by NotificationID in the
		///		NotificationsByImei table. Table Imei is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationsByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_notificationId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByNotificationIdFromNotificationsByImei(TransactionManager transactionManager, System.Int32 _notificationId,int start, int pageLength)
		{
			int count = -1;
			return GetByNotificationIdFromNotificationsByImei(transactionManager, _notificationId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets Imei objects from the datasource by NotificationID in the
		///		NotificationsByImei table. Table Imei is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationsByImei table.
		/// </summary>
		/// <param name="_notificationId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Imei objects.</returns>
		public TList<Imei> GetByNotificationIdFromNotificationsByImei(System.Int32 _notificationId,int start, int pageLength, out int count)
		{
			
			return GetByNotificationIdFromNotificationsByImei(null, _notificationId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets Imei objects from the datasource by NotificationID in the
		///		NotificationsByImei table. Table Imei is related to table Notifications
		///		through the (M:N) relationship defined in the NotificationsByImei table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_notificationId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of Imei objects.</returns>
		public abstract TList<Imei> GetByNotificationIdFromNotificationsByImei(TransactionManager transactionManager,System.Int32 _notificationId, int start, int pageLength, out int count);
		
		#endregion GetByNotificationIdFromNotificationsByImei
		
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, GPSTrackingServerDB.Entities.ImeiKey key)
		{
			return Delete(transactionManager, key.Imei);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_imei">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.String _imei)
		{
			return Delete(null, _imei);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_imei">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.String _imei);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_GPSModels key.
		///		FK_Imei_GPSModels Description: 
		/// </summary>
		/// <param name="_gpsModelId"></param>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public TList<Imei> GetByGpsModelId(System.Int16 _gpsModelId)
		{
			int count = -1;
			return GetByGpsModelId(_gpsModelId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_GPSModels key.
		///		FK_Imei_GPSModels Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsModelId"></param>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		/// <remarks></remarks>
		public TList<Imei> GetByGpsModelId(TransactionManager transactionManager, System.Int16 _gpsModelId)
		{
			int count = -1;
			return GetByGpsModelId(transactionManager, _gpsModelId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_GPSModels key.
		///		FK_Imei_GPSModels Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsModelId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public TList<Imei> GetByGpsModelId(TransactionManager transactionManager, System.Int16 _gpsModelId, int start, int pageLength)
		{
			int count = -1;
			return GetByGpsModelId(transactionManager, _gpsModelId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_GPSModels key.
		///		fkImeiGpsModels Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_gpsModelId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public TList<Imei> GetByGpsModelId(System.Int16 _gpsModelId, int start, int pageLength)
		{
			int count =  -1;
			return GetByGpsModelId(null, _gpsModelId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_GPSModels key.
		///		fkImeiGpsModels Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_gpsModelId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public TList<Imei> GetByGpsModelId(System.Int16 _gpsModelId, int start, int pageLength,out int count)
		{
			return GetByGpsModelId(null, _gpsModelId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_GPSModels key.
		///		FK_Imei_GPSModels Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_gpsModelId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public abstract TList<Imei> GetByGpsModelId(TransactionManager transactionManager, System.Int16 _gpsModelId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_VehicleType key.
		///		FK_Imei_VehicleType Description: 
		/// </summary>
		/// <param name="_imeiTypeId"></param>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public TList<Imei> GetByImeiTypeId(System.Int32 _imeiTypeId)
		{
			int count = -1;
			return GetByImeiTypeId(_imeiTypeId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_VehicleType key.
		///		FK_Imei_VehicleType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_imeiTypeId"></param>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		/// <remarks></remarks>
		public TList<Imei> GetByImeiTypeId(TransactionManager transactionManager, System.Int32 _imeiTypeId)
		{
			int count = -1;
			return GetByImeiTypeId(transactionManager, _imeiTypeId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_VehicleType key.
		///		FK_Imei_VehicleType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_imeiTypeId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public TList<Imei> GetByImeiTypeId(TransactionManager transactionManager, System.Int32 _imeiTypeId, int start, int pageLength)
		{
			int count = -1;
			return GetByImeiTypeId(transactionManager, _imeiTypeId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_VehicleType key.
		///		fkImeiVehicleType Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_imeiTypeId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public TList<Imei> GetByImeiTypeId(System.Int32 _imeiTypeId, int start, int pageLength)
		{
			int count =  -1;
			return GetByImeiTypeId(null, _imeiTypeId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_VehicleType key.
		///		fkImeiVehicleType Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_imeiTypeId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public TList<Imei> GetByImeiTypeId(System.Int32 _imeiTypeId, int start, int pageLength,out int count)
		{
			return GetByImeiTypeId(null, _imeiTypeId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Imei_VehicleType key.
		///		FK_Imei_VehicleType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_imeiTypeId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of GPSTrackingServerDB.Entities.Imei objects.</returns>
		public abstract TList<Imei> GetByImeiTypeId(TransactionManager transactionManager, System.Int32 _imeiTypeId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override GPSTrackingServerDB.Entities.Imei Get(TransactionManager transactionManager, GPSTrackingServerDB.Entities.ImeiKey key, int start, int pageLength)
		{
			return GetByImei(transactionManager, key.Imei, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_Track_Detail index.
		/// </summary>
		/// <param name="_imei"></param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingServerDB.Entities.Imei"/> class.</returns>
		public GPSTrackingServerDB.Entities.Imei GetByImei(System.String _imei)
		{
			int count = -1;
			return GetByImei(null,_imei, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Track_Detail index.
		/// </summary>
		/// <param name="_imei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingServerDB.Entities.Imei"/> class.</returns>
		public GPSTrackingServerDB.Entities.Imei GetByImei(System.String _imei, int start, int pageLength)
		{
			int count = -1;
			return GetByImei(null, _imei, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Track_Detail index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_imei"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingServerDB.Entities.Imei"/> class.</returns>
		public GPSTrackingServerDB.Entities.Imei GetByImei(TransactionManager transactionManager, System.String _imei)
		{
			int count = -1;
			return GetByImei(transactionManager, _imei, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Track_Detail index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_imei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingServerDB.Entities.Imei"/> class.</returns>
		public GPSTrackingServerDB.Entities.Imei GetByImei(TransactionManager transactionManager, System.String _imei, int start, int pageLength)
		{
			int count = -1;
			return GetByImei(transactionManager, _imei, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Track_Detail index.
		/// </summary>
		/// <param name="_imei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="GPSTrackingServerDB.Entities.Imei"/> class.</returns>
		public GPSTrackingServerDB.Entities.Imei GetByImei(System.String _imei, int start, int pageLength, out int count)
		{
			return GetByImei(null, _imei, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Track_Detail index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_imei"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="GPSTrackingServerDB.Entities.Imei"/> class.</returns>
		public abstract GPSTrackingServerDB.Entities.Imei GetByImei(TransactionManager transactionManager, System.String _imei, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;Imei&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;Imei&gt;"/></returns>
		public static TList<Imei> Fill(IDataReader reader, TList<Imei> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				GPSTrackingServerDB.Entities.Imei c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("Imei")
					.Append("|").Append((System.String)reader[((int)ImeiColumn.Imei - 1)]).ToString();
					c = EntityManager.LocateOrCreate<Imei>(
					key.ToString(), // EntityTrackingKey
					"Imei",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new GPSTrackingServerDB.Entities.Imei();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.Imei = (System.String)reader[((int)ImeiColumn.Imei - 1)];
					c.OriginalImei = c.Imei;
					c.Name = (reader.IsDBNull(((int)ImeiColumn.Name - 1)))?null:(System.String)reader[((int)ImeiColumn.Name - 1)];
					c.SimNumber = (reader.IsDBNull(((int)ImeiColumn.SimNumber - 1)))?null:(System.Decimal?)reader[((int)ImeiColumn.SimNumber - 1)];
					c.Description = (reader.IsDBNull(((int)ImeiColumn.Description - 1)))?null:(System.String)reader[((int)ImeiColumn.Description - 1)];
					c.ImeiTypeId = (System.Int32)reader[((int)ImeiColumn.ImeiTypeId - 1)];
					c.GpsModelId = (System.Int16)reader[((int)ImeiColumn.GpsModelId - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingServerDB.Entities.Imei"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingServerDB.Entities.Imei"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, GPSTrackingServerDB.Entities.Imei entity)
		{
			if (!reader.Read()) return;
			
			entity.Imei = (System.String)reader[((int)ImeiColumn.Imei - 1)];
			entity.OriginalImei = (System.String)reader["Imei"];
			entity.Name = (reader.IsDBNull(((int)ImeiColumn.Name - 1)))?null:(System.String)reader[((int)ImeiColumn.Name - 1)];
			entity.SimNumber = (reader.IsDBNull(((int)ImeiColumn.SimNumber - 1)))?null:(System.Decimal?)reader[((int)ImeiColumn.SimNumber - 1)];
			entity.Description = (reader.IsDBNull(((int)ImeiColumn.Description - 1)))?null:(System.String)reader[((int)ImeiColumn.Description - 1)];
			entity.ImeiTypeId = (System.Int32)reader[((int)ImeiColumn.ImeiTypeId - 1)];
			entity.GpsModelId = (System.Int16)reader[((int)ImeiColumn.GpsModelId - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="GPSTrackingServerDB.Entities.Imei"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="GPSTrackingServerDB.Entities.Imei"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, GPSTrackingServerDB.Entities.Imei entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Imei = (System.String)dataRow["Imei"];
			entity.OriginalImei = (System.String)dataRow["Imei"];
			entity.Name = Convert.IsDBNull(dataRow["Name"]) ? null : (System.String)dataRow["Name"];
			entity.SimNumber = Convert.IsDBNull(dataRow["SimNumber"]) ? null : (System.Decimal?)dataRow["SimNumber"];
			entity.Description = Convert.IsDBNull(dataRow["Description"]) ? null : (System.String)dataRow["Description"];
			entity.ImeiTypeId = (System.Int32)dataRow["ImeiTypeID"];
			entity.GpsModelId = (System.Int16)dataRow["GPSModelID"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="GPSTrackingServerDB.Entities.Imei"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">GPSTrackingServerDB.Entities.Imei Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, GPSTrackingServerDB.Entities.Imei entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region GpsModelIdSource	
			if (CanDeepLoad(entity, "GpsModels|GpsModelIdSource", deepLoadType, innerList) 
				&& entity.GpsModelIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.GpsModelId;
				GpsModels tmpEntity = EntityManager.LocateEntity<GpsModels>(EntityLocator.ConstructKeyFromPkItems(typeof(GpsModels), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.GpsModelIdSource = tmpEntity;
				else
					entity.GpsModelIdSource = DataRepository.GpsModelsProvider.GetByGpsModelId(transactionManager, entity.GpsModelId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GpsModelIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.GpsModelIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.GpsModelsProvider.DeepLoad(transactionManager, entity.GpsModelIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion GpsModelIdSource

			#region ImeiTypeIdSource	
			if (CanDeepLoad(entity, "ImeiType|ImeiTypeIdSource", deepLoadType, innerList) 
				&& entity.ImeiTypeIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.ImeiTypeId;
				ImeiType tmpEntity = EntityManager.LocateEntity<ImeiType>(EntityLocator.ConstructKeyFromPkItems(typeof(ImeiType), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.ImeiTypeIdSource = tmpEntity;
				else
					entity.ImeiTypeIdSource = DataRepository.ImeiTypeProvider.GetByImeiTypeId(transactionManager, entity.ImeiTypeId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'ImeiTypeIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.ImeiTypeIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.ImeiTypeProvider.DeepLoad(transactionManager, entity.ImeiTypeIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion ImeiTypeIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByImei methods when available
			
			#region TrackDataLastLocation
			// RelationshipType.OneToOne
			if (CanDeepLoad(entity, "TrackDataLastLocation|TrackDataLastLocation", deepLoadType, innerList))
			{
				entity.TrackDataLastLocation = DataRepository.TrackDataLastLocationProvider.GetByImei(transactionManager, entity.Imei);
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'TrackDataLastLocation' loaded. key " + entity.EntityTrackingKey);
				#endif 

				if (deep && entity.TrackDataLastLocation != null)
				{
					deepHandles.Add("TrackDataLastLocation",
						new KeyValuePair<Delegate, object>((DeepLoadSingleHandle< TrackDataLastLocation >) DataRepository.TrackDataLastLocationProvider.DeepLoad,
						new object[] { transactionManager, entity.TrackDataLastLocation, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion 
			
			
			
			#region NotificationsByImeiCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<NotificationsByImei>|NotificationsByImeiCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'NotificationsByImeiCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.NotificationsByImeiCollection = DataRepository.NotificationsByImeiProvider.GetByImei(transactionManager, entity.Imei);

				if (deep && entity.NotificationsByImeiCollection.Count > 0)
				{
					deepHandles.Add("NotificationsByImeiCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<NotificationsByImei>) DataRepository.NotificationsByImeiProvider.DeepLoad,
						new object[] { transactionManager, entity.NotificationsByImeiCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region GroupsByImeiCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<GroupsByImei>|GroupsByImeiCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GroupsByImeiCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.GroupsByImeiCollection = DataRepository.GroupsByImeiProvider.GetByImei(transactionManager, entity.Imei);

				if (deep && entity.GroupsByImeiCollection.Count > 0)
				{
					deepHandles.Add("GroupsByImeiCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<GroupsByImei>) DataRepository.GroupsByImeiProvider.DeepLoad,
						new object[] { transactionManager, entity.GroupsByImeiCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region NotificationIdNotificationsCollection_From_NotificationsByImei
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<Notifications>|NotificationIdNotificationsCollection_From_NotificationsByImei", deepLoadType, innerList))
			{
				entity.NotificationIdNotificationsCollection_From_NotificationsByImei = DataRepository.NotificationsProvider.GetByImeiFromNotificationsByImei(transactionManager, entity.Imei);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'NotificationIdNotificationsCollection_From_NotificationsByImei' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.NotificationIdNotificationsCollection_From_NotificationsByImei != null)
				{
					deepHandles.Add("NotificationIdNotificationsCollection_From_NotificationsByImei",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< Notifications >) DataRepository.NotificationsProvider.DeepLoad,
						new object[] { transactionManager, entity.NotificationIdNotificationsCollection_From_NotificationsByImei, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region GeoFenceIdGeoFenceCollection_From_GeoFenceByImei
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<GeoFence>|GeoFenceIdGeoFenceCollection_From_GeoFenceByImei", deepLoadType, innerList))
			{
				entity.GeoFenceIdGeoFenceCollection_From_GeoFenceByImei = DataRepository.GeoFenceProvider.GetByImeiFromGeoFenceByImei(transactionManager, entity.Imei);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GeoFenceIdGeoFenceCollection_From_GeoFenceByImei' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.GeoFenceIdGeoFenceCollection_From_GeoFenceByImei != null)
				{
					deepHandles.Add("GeoFenceIdGeoFenceCollection_From_GeoFenceByImei",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< GeoFence >) DataRepository.GeoFenceProvider.DeepLoad,
						new object[] { transactionManager, entity.GeoFenceIdGeoFenceCollection_From_GeoFenceByImei, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region GroupIdGroupsCollection_From_GroupsByImei
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<Groups>|GroupIdGroupsCollection_From_GroupsByImei", deepLoadType, innerList))
			{
				entity.GroupIdGroupsCollection_From_GroupsByImei = DataRepository.GroupsProvider.GetByImeiFromGroupsByImei(transactionManager, entity.Imei);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GroupIdGroupsCollection_From_GroupsByImei' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.GroupIdGroupsCollection_From_GroupsByImei != null)
				{
					deepHandles.Add("GroupIdGroupsCollection_From_GroupsByImei",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< Groups >) DataRepository.GroupsProvider.DeepLoad,
						new object[] { transactionManager, entity.GroupIdGroupsCollection_From_GroupsByImei, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region GeoFenceByImeiCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<GeoFenceByImei>|GeoFenceByImeiCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'GeoFenceByImeiCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.GeoFenceByImeiCollection = DataRepository.GeoFenceByImeiProvider.GetByImei(transactionManager, entity.Imei);

				if (deep && entity.GeoFenceByImeiCollection.Count > 0)
				{
					deepHandles.Add("GeoFenceByImeiCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<GeoFenceByImei>) DataRepository.GeoFenceByImeiProvider.DeepLoad,
						new object[] { transactionManager, entity.GeoFenceByImeiCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PendingComandCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PendingComand>|PendingComandCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PendingComandCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PendingComandCollection = DataRepository.PendingComandProvider.GetByImei(transactionManager, entity.Imei);

				if (deep && entity.PendingComandCollection.Count > 0)
				{
					deepHandles.Add("PendingComandCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PendingComand>) DataRepository.PendingComandProvider.DeepLoad,
						new object[] { transactionManager, entity.PendingComandCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the GPSTrackingServerDB.Entities.Imei object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">GPSTrackingServerDB.Entities.Imei instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">GPSTrackingServerDB.Entities.Imei Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, GPSTrackingServerDB.Entities.Imei entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region GpsModelIdSource
			if (CanDeepSave(entity, "GpsModels|GpsModelIdSource", deepSaveType, innerList) 
				&& entity.GpsModelIdSource != null)
			{
				DataRepository.GpsModelsProvider.Save(transactionManager, entity.GpsModelIdSource);
				entity.GpsModelId = entity.GpsModelIdSource.GpsModelId;
			}
			#endregion 
			
			#region ImeiTypeIdSource
			if (CanDeepSave(entity, "ImeiType|ImeiTypeIdSource", deepSaveType, innerList) 
				&& entity.ImeiTypeIdSource != null)
			{
				DataRepository.ImeiTypeProvider.Save(transactionManager, entity.ImeiTypeIdSource);
				entity.ImeiTypeId = entity.ImeiTypeIdSource.ImeiTypeId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();

			#region TrackDataLastLocation
			if (CanDeepSave(entity.TrackDataLastLocation, "TrackDataLastLocation|TrackDataLastLocation", deepSaveType, innerList))
			{

				if (entity.TrackDataLastLocation != null)
				{
					// update each child parent id with the real parent id (mostly used on insert)

					entity.TrackDataLastLocation.Imei = entity.Imei;
					//DataRepository.TrackDataLastLocationProvider.Save(transactionManager, entity.TrackDataLastLocation);
					deepHandles.Add("TrackDataLastLocation",
						new KeyValuePair<Delegate, object>((DeepSaveSingleHandle< TrackDataLastLocation >) DataRepository.TrackDataLastLocationProvider.DeepSave,
						new object[] { transactionManager, entity.TrackDataLastLocation, deepSaveType, childTypes, innerList }
					));
				}
			} 
			#endregion 

			#region NotificationIdNotificationsCollection_From_NotificationsByImei>
			if (CanDeepSave(entity.NotificationIdNotificationsCollection_From_NotificationsByImei, "List<Notifications>|NotificationIdNotificationsCollection_From_NotificationsByImei", deepSaveType, innerList))
			{
				if (entity.NotificationIdNotificationsCollection_From_NotificationsByImei.Count > 0 || entity.NotificationIdNotificationsCollection_From_NotificationsByImei.DeletedItems.Count > 0)
				{
					DataRepository.NotificationsProvider.Save(transactionManager, entity.NotificationIdNotificationsCollection_From_NotificationsByImei); 
					deepHandles.Add("NotificationIdNotificationsCollection_From_NotificationsByImei",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<Notifications>) DataRepository.NotificationsProvider.DeepSave,
						new object[] { transactionManager, entity.NotificationIdNotificationsCollection_From_NotificationsByImei, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region GeoFenceIdGeoFenceCollection_From_GeoFenceByImei>
			if (CanDeepSave(entity.GeoFenceIdGeoFenceCollection_From_GeoFenceByImei, "List<GeoFence>|GeoFenceIdGeoFenceCollection_From_GeoFenceByImei", deepSaveType, innerList))
			{
				if (entity.GeoFenceIdGeoFenceCollection_From_GeoFenceByImei.Count > 0 || entity.GeoFenceIdGeoFenceCollection_From_GeoFenceByImei.DeletedItems.Count > 0)
				{
					DataRepository.GeoFenceProvider.Save(transactionManager, entity.GeoFenceIdGeoFenceCollection_From_GeoFenceByImei); 
					deepHandles.Add("GeoFenceIdGeoFenceCollection_From_GeoFenceByImei",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<GeoFence>) DataRepository.GeoFenceProvider.DeepSave,
						new object[] { transactionManager, entity.GeoFenceIdGeoFenceCollection_From_GeoFenceByImei, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 

			#region GroupIdGroupsCollection_From_GroupsByImei>
			if (CanDeepSave(entity.GroupIdGroupsCollection_From_GroupsByImei, "List<Groups>|GroupIdGroupsCollection_From_GroupsByImei", deepSaveType, innerList))
			{
				if (entity.GroupIdGroupsCollection_From_GroupsByImei.Count > 0 || entity.GroupIdGroupsCollection_From_GroupsByImei.DeletedItems.Count > 0)
				{
					DataRepository.GroupsProvider.Save(transactionManager, entity.GroupIdGroupsCollection_From_GroupsByImei); 
					deepHandles.Add("GroupIdGroupsCollection_From_GroupsByImei",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<Groups>) DataRepository.GroupsProvider.DeepSave,
						new object[] { transactionManager, entity.GroupIdGroupsCollection_From_GroupsByImei, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 
	
			#region List<NotificationsByImei>
				if (CanDeepSave(entity.NotificationsByImeiCollection, "List<NotificationsByImei>|NotificationsByImeiCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(NotificationsByImei child in entity.NotificationsByImeiCollection)
					{
						if(child.ImeiSource != null)
						{
								child.Imei = child.ImeiSource.Imei;
						}

						if(child.NotificationIdSource != null)
						{
								child.NotificationId = child.NotificationIdSource.NotificationId;
						}

					}

					if (entity.NotificationsByImeiCollection.Count > 0 || entity.NotificationsByImeiCollection.DeletedItems.Count > 0)
					{
						//DataRepository.NotificationsByImeiProvider.Save(transactionManager, entity.NotificationsByImeiCollection);
						
						deepHandles.Add("NotificationsByImeiCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< NotificationsByImei >) DataRepository.NotificationsByImeiProvider.DeepSave,
							new object[] { transactionManager, entity.NotificationsByImeiCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<GroupsByImei>
				if (CanDeepSave(entity.GroupsByImeiCollection, "List<GroupsByImei>|GroupsByImeiCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(GroupsByImei child in entity.GroupsByImeiCollection)
					{
						if(child.ImeiSource != null)
						{
								child.Imei = child.ImeiSource.Imei;
						}

						if(child.GroupIdSource != null)
						{
								child.GroupId = child.GroupIdSource.GroupId;
						}

					}

					if (entity.GroupsByImeiCollection.Count > 0 || entity.GroupsByImeiCollection.DeletedItems.Count > 0)
					{
						//DataRepository.GroupsByImeiProvider.Save(transactionManager, entity.GroupsByImeiCollection);
						
						deepHandles.Add("GroupsByImeiCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< GroupsByImei >) DataRepository.GroupsByImeiProvider.DeepSave,
							new object[] { transactionManager, entity.GroupsByImeiCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<GeoFenceByImei>
				if (CanDeepSave(entity.GeoFenceByImeiCollection, "List<GeoFenceByImei>|GeoFenceByImeiCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(GeoFenceByImei child in entity.GeoFenceByImeiCollection)
					{
						if(child.ImeiSource != null)
						{
								child.Imei = child.ImeiSource.Imei;
						}

						if(child.GeoFenceIdSource != null)
						{
								child.GeoFenceId = child.GeoFenceIdSource.GeoFenceId;
						}

					}

					if (entity.GeoFenceByImeiCollection.Count > 0 || entity.GeoFenceByImeiCollection.DeletedItems.Count > 0)
					{
						//DataRepository.GeoFenceByImeiProvider.Save(transactionManager, entity.GeoFenceByImeiCollection);
						
						deepHandles.Add("GeoFenceByImeiCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< GeoFenceByImei >) DataRepository.GeoFenceByImeiProvider.DeepSave,
							new object[] { transactionManager, entity.GeoFenceByImeiCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<PendingComand>
				if (CanDeepSave(entity.PendingComandCollection, "List<PendingComand>|PendingComandCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PendingComand child in entity.PendingComandCollection)
					{
						if(child.ImeiSource != null)
						{
							child.Imei = child.ImeiSource.Imei;
						}
						else
						{
							child.Imei = entity.Imei;
						}

					}

					if (entity.PendingComandCollection.Count > 0 || entity.PendingComandCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PendingComandProvider.Save(transactionManager, entity.PendingComandCollection);
						
						deepHandles.Add("PendingComandCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PendingComand >) DataRepository.PendingComandProvider.DeepSave,
							new object[] { transactionManager, entity.PendingComandCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region ImeiChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>GPSTrackingServerDB.Entities.Imei</c>
	///</summary>
	public enum ImeiChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>GpsModels</c> at GpsModelIdSource
		///</summary>
		[ChildEntityType(typeof(GpsModels))]
		GpsModels,
		
		///<summary>
		/// Composite Property for <c>ImeiType</c> at ImeiTypeIdSource
		///</summary>
		[ChildEntityType(typeof(ImeiType))]
		ImeiType,
		///<summary>
		/// Entity <c>TrackDataLastLocation</c> as OneToOne for TrackDataLastLocation
		///</summary>
		[ChildEntityType(typeof(TrackDataLastLocation))]
		TrackDataLastLocation,
		///<summary>
		/// Collection of <c>Imei</c> as OneToMany for NotificationsByImeiCollection
		///</summary>
		[ChildEntityType(typeof(TList<NotificationsByImei>))]
		NotificationsByImeiCollection,
		///<summary>
		/// Collection of <c>Imei</c> as OneToMany for GroupsByImeiCollection
		///</summary>
		[ChildEntityType(typeof(TList<GroupsByImei>))]
		GroupsByImeiCollection,
		///<summary>
		/// Collection of <c>Imei</c> as ManyToMany for NotificationsCollection_From_NotificationsByImei
		///</summary>
		[ChildEntityType(typeof(TList<Notifications>))]
		NotificationIdNotificationsCollection_From_NotificationsByImei,
		///<summary>
		/// Collection of <c>Imei</c> as ManyToMany for GeoFenceCollection_From_GeoFenceByImei
		///</summary>
		[ChildEntityType(typeof(TList<GeoFence>))]
		GeoFenceIdGeoFenceCollection_From_GeoFenceByImei,
		///<summary>
		/// Collection of <c>Imei</c> as ManyToMany for GroupsCollection_From_GroupsByImei
		///</summary>
		[ChildEntityType(typeof(TList<Groups>))]
		GroupIdGroupsCollection_From_GroupsByImei,
		///<summary>
		/// Collection of <c>Imei</c> as OneToMany for GeoFenceByImeiCollection
		///</summary>
		[ChildEntityType(typeof(TList<GeoFenceByImei>))]
		GeoFenceByImeiCollection,
		///<summary>
		/// Collection of <c>Imei</c> as OneToMany for PendingComandCollection
		///</summary>
		[ChildEntityType(typeof(TList<PendingComand>))]
		PendingComandCollection,
	}
	
	#endregion ImeiChildEntityTypes
	
	#region ImeiFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;ImeiColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Imei"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ImeiFilterBuilder : SqlFilterBuilder<ImeiColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ImeiFilterBuilder class.
		/// </summary>
		public ImeiFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ImeiFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ImeiFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ImeiFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ImeiFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ImeiFilterBuilder
	
	#region ImeiParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;ImeiColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Imei"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ImeiParameterBuilder : ParameterizedSqlFilterBuilder<ImeiColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ImeiParameterBuilder class.
		/// </summary>
		public ImeiParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ImeiParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ImeiParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ImeiParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ImeiParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ImeiParameterBuilder
	
	#region ImeiSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;ImeiColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Imei"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class ImeiSortBuilder : SqlSortBuilder<ImeiColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ImeiSqlSortBuilder class.
		/// </summary>
		public ImeiSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion ImeiSortBuilder
	
} // end namespace
